﻿using System;
using System.Collections.Generic;
using br.com.SistemaChamados.DAO;
using br.com.SistemaChamados.Enum;
using br.com.SistemaChamados.Model;

namespace br.com.SistemaChamados.Controller
{
    public class CallSubCategoryController
    {
        /// <summary>
        /// Método responsável por inserir uma subcategoria de chamado na base de dados
        /// </summary>
        /// <param name="callSubCategory">A subcategoria a ser inserida</param>
        /// <returns>EnumGenericState</returns>
        public EnumGenericState InsertCallSubCategory(CallSubCategory callSubCategory)
        {
            EnumGenericState stateTransaction = EnumGenericState.GENERIC_STATE_UNKNOW;
            try
            {
                stateTransaction = CallSubCategoryDAO.InsertCallSubCategory(callSubCategory);
            }
            catch (Exception ex)
            {
                stateTransaction = EnumGenericState.GENERIC_STATE_FAILED;
                throw ex;
            }
            return stateTransaction;
        }

        /// <summary>
        /// Método para atualizar a subcatgoria de chamado
        /// </summary>
        /// <param name="callSubCategory">A subcategoria de chamado com as informações a serem atualizadas</param>
        /// <returns>EnumGenericState</returns>
        public EnumGenericState UpdateCallSubCategory(CallSubCategory callSubCategory)
        {
            EnumGenericState stateTransaction = EnumGenericState.GENERIC_STATE_UNKNOW;
            try
            {
                stateTransaction = CallSubCategoryDAO.UpdateCallSubCategory(callSubCategory);
            }
            catch (Exception ex)
            {
                stateTransaction = EnumGenericState.GENERIC_STATE_FAILED;
                throw ex;
            }
            return stateTransaction;
        }

        /// <summary>
        /// Método para deletar uma subcategoria
        /// </summary>
        /// <param name="callSubCategory">Subcategoria a ser excluída</param>
        /// <returns>EnumGenericState</returns>
        public EnumGenericState DeleteCallSubCategory(CallSubCategory callSubCategory)
        {
            EnumGenericState stateTransaction = EnumGenericState.GENERIC_STATE_UNKNOW;
            try
            {
                stateTransaction = CallSubCategoryDAO.DeleteCallSubCategory(callSubCategory);
            }
            catch (Exception ex)
            {
                stateTransaction = EnumGenericState.GENERIC_STATE_FAILED;
                throw ex;
            }
            return stateTransaction;
        }

        /// <summary>
        /// Método que retorna todas as subcategorias vinculadas a uma categoria de chamado
        /// </summary>
        /// <param name="callSubCategory">A categoria da qual se deseja obter as subcategorias</param>
        /// <returns>List - CallSubCategory</returns>
        public List<CallSubCategory> GetCallSubCategoriesByCallCategory(CallSubCategory callSubCategory)
        {
            List<CallSubCategory> listCallSubCategory = new List<CallSubCategory>();
            try
            {
                listCallSubCategory = CallSubCategoryDAO.getCallSubCategoriesByCallCategory(callSubCategory);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return listCallSubCategory;
        }

        /// <summary>
        /// Método que retorna uma subcategoria desejada
        /// </summary>
        /// <param name="callSubCategory">A subcategoria-alvo com o Id</param>
        /// <returns>CallSubCategory</returns>
        public CallSubCategory GetCallSubCategory(CallSubCategory callSubCategory)
        {
            CallSubCategory newCallSubCategory = new CallSubCategory();
            try
            {
                newCallSubCategory = CallSubCategoryDAO.getCallSubCategory(callSubCategory.Id);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return newCallSubCategory;
        }

        /// <summary>
        /// Método responsável por retornar todas as subcategorias de chamado
        /// </summary>
        /// <returns>List - CallSubCategory</returns>
        public List<CallSubCategory> GetCallSubCategories()
        {
            List<CallSubCategory> listCallCategories = new List<CallSubCategory>();

            try
            {
                listCallCategories = CallSubCategoryDAO.getCallSubCategories();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return listCallCategories;
        }

        public CallSubCategoryController()
        {

        }
    }
}